package com.gogowan.agroenterprise.utils;

import android.app.ActionBar;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;


public class PopupWindowUtil {
    private  PopupWindowUtil util;
    private PopupWindow popupWindow;
    private Activity activity;
    private LayoutInflater inflater;
    private View view;
    public PopupWindowUtil(Activity activity){
        this.activity=activity;
        inflater= LayoutInflater.from(this.activity);
    }
    public  PopupWindowUtil setContextView(int layoutId){
        view=inflater.inflate(layoutId,null);
        return this;
    }
    public PopupWindowUtil setType(int width,int height){
        if(width==0){
            width= ActionBar.LayoutParams.MATCH_PARENT;
        }
        if (height==0){
            height= ActionBar.LayoutParams.MATCH_PARENT;
        }
        popupWindow=new PopupWindow(view,width,height);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setFocusable(true);
        popupWindow.setTouchable(true);
        return this;
    }
    public View getView(){
        return view;
    }
    public void show(int gravity,int x,int y){
//        (Gravity.BOTTOM,0,0
        popupWindow.showAtLocation(view,gravity,x,y);
    }
    public void show2(int gravity,int x,int y){
//        (Gravity.BOTTOM,0,0
        popupWindow.showAsDropDown(view,gravity,x,y);
    }
    public PopupWindow getPopupWindow(){
        return popupWindow;
    }
}
